package com.yinhai.util;

public class PhoneSearchFunction {
	
	private static char GetSearchNum(char ch) {
		if(ch >= '0' && ch <= '9') {
			return ch;
		}
		if(ch >= 'a' && ch <= 'z') {
			int i = (int)(ch - 'a');
			if(i < 18) {
				return (char)(i / 3 + 2 + '0');
			}
			if(i == 18)
				return '7';
			if(i >= 19 && i <= 21)
				return '8';
			return '9';
		} else {
			return 0;
		}
	}
	
	public static String GetSearchStr(String name) {
		StringBuilder buf = new StringBuilder();
		int len = name.length();
		char ch = 0;
		for(int i = 0; i < len; ++i) {
			ch = GetSearchNum(name.charAt(i));
			if(ch != 0) {
				buf.append(ch);
			}
		}
		return buf.toString();
	}

}
